package ace.module.oss.core.impl.manager.impl;

import ace.cmp.core.constants.CoreConstant;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.cmp.i18n.api.MessageSourceAssertService;
import ace.cmp.json.api.JsonService;
import ace.module.oss.api.model.dto.OssSupplierDto;
import ace.module.oss.core.impl.dao.entity.OssSupplier;
import ace.module.oss.core.impl.dao.repository.OssSupplierRepository;
import ace.module.oss.core.impl.manager.OssSupplierManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.x.file.storage.core.FileStorageProperties;
import org.springframework.stereotype.Component;

/**
 * Oss供应商 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class OssSupplierManagerImpl
    extends AbstractSpringDtoManager<OssSupplier, Long,  OssSupplierDto>
    implements OssSupplierManager {

  private final OssSupplierRepository ossSupplierRepository;
  private final MessageSourceAssertService assertService;
  private final JsonService jsonService;

  @Override
  public OssSupplier getAndCheckById(Long id) {
    OssSupplier ossSupplier = this.ossSupplierRepository.getById(id);
    assertService.isNull(ossSupplier, OssSupplier.class.getName() + ".error-is-null", "供应商配置不存在");
    assertService.isFalse(
        ossSupplier.getDeleteFlag().equals(CoreConstant.DELETE_FLAG_NOT),
        ".error-is-null",
        "供应商配置不存在");
    return ossSupplier;
  }

  @Override
  public String getDefaultAliyunConfigWithoutSecret() {
    FileStorageProperties.AliyunOssConfig config = new FileStorageProperties.AliyunOssConfig();
    String configString = jsonService.toJson(config);
    return configString;
  }
}
